(function() {
  'use strict';

  angular
    .module('hp')
    .controller('LoginController', LoginController)
    .controller('LogoutController', LogoutController);

  /** @ngInject */
  function LoginController($log, webDevTec, toastr,$state,$scope,LoginService,MyAuth,$rootScope) {
    var vm = this;
    vm.qq='';
    vm.password='';
    vm.submit = submit;
    vm.invalid = false


    function submit(){
        $log.debug('login'+JSON.stringify(vm))
        if(vm.qq == '' || vm.password == ''){
            vm.invalid = true;
            return;
        }else{
            vm.invalid = false
        }
        
        LoginService.post({},{body:{qq:vm.qq,password:vm.password}}).$promise.then(function(data){
            // 这里写你登录后的逻辑
            var c = data || {};
            var code = c.head.errorCode + '';
            if (code == '200'){
                    MyAuth.setData('token',c.body.token)
                    $rootScope.isLogin = MyAuth.loggedIn();
                    $state.go('machinecode');
            }else{
                console.log(c.head)
                    toastr.info('有情况：' + c.head.errorMsg);
            }
        },function(err){
            toastr.info('服务器正忙!'+err)
            $log.debug(err);
        });

    }

  }

  function LogoutController($state,MyAuth,$rootScope){
      var vm = this;
      MyAuth.Logout();
      $state.go('home')
      $rootScope.isLogin = MyAuth.loggedIn();
  }

})();
